package reflect;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        Person p = new Person();
        p.dance();

//        Class cls = Class.forName("reflect.Person");
//        Object obj = cls.newInstance();
//
//        Method method = cls.getMethod("dance");
//        method.invoke(obj);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入包名");
        String className = scanner.nextLine();
        Class cls = Class.forName(className);

        Object obj = cls.newInstance();
        System.out.println("请输入方法名");
        String methodName = scanner.nextLine();
        Method method = cls.getMethod(methodName);
        method.invoke(obj);
    }
}
